package cn.source.zk.domain.dto;

import cn.source.zk.domain.entity.DBIhrja;
import cn.source.zk.domain.entity.DBIhrjb;
import cn.source.zk.domain.entity.DBIhrjc;
import lombok.Data;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shiqi
 * @create 2025-04-27 11:19
 */
@Data
public class DBIhrjDTO {

    private LocalDateTime timedate;

    private Map<String, Object> fields = new HashMap<String, Object>();

    //构建db_ihra表
    public void buildToIhrja(DBIhrja dbIhrja, Map<Integer,String> fieldNames){
        if(dbIhrja != null){
            this.timedate = dbIhrja.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhrja.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("a_"+v, field.get(dbIhrja));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

    public void buildToIhrjb(DBIhrjb dbIhrjb, Map<Integer,String> fieldNames){
        if(dbIhrjb != null){
            this.timedate = dbIhrjb.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhrjb.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("b_"+v, field.get(dbIhrjb));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

    public void buildToIhrjc(DBIhrjc dbIhrjc, Map<Integer,String> fieldNames){
        if(dbIhrjc != null){
            this.timedate = dbIhrjc.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){

                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhrjc.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("c_"+v, field.get(dbIhrjc));
                    } catch (Exception e){

                    }
                });
            }
        }
    }

}
